package com.atguigu.java8.demo;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by Smexy on 2022/9/8
 */
public class StreamDemo
{
    public static void main(String[] args) {

        //有一个要处理的数据集合
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);

        //封装为Stream才能操作
        Stream<Integer> s1 = list.stream();

        //转换操作
       /* Stream<Integer> s2 = s1.map(new Function<Integer, Integer>()
        {
            //将输入的integer如何运算后输出
            @Override
            public Integer apply(Integer num) {
                return num + 10;
            }
        });*/


        Stream<Integer> s2 = s1.map((Integer num) -> {
            return num + 10;
        });

        //Stream<Integer> s2 = s1.map(num -> num + 10);

        //等行动算子(终止操作)触发
        //收集计算的结果
        List<Integer> result = s2.collect(Collectors.toList());

        System.out.println(result);


    }
}
